package homework1;

import java.util.Scanner;

/**
 *邮箱登录
 */
public class EmailLoginImpl implements LoginStrategy{
    @Override
    public void login() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你的邮箱");
        String email = sc.nextLine();

        while (true) {
            // 邮箱必须合法
            if (isValidEmail(email)) {
                System.out.println("登录成功！");
                //进入相应的系统
                break;
            } else {
                System.out.println("邮箱错误！,请重新输入");
            }
        }
    }

    private boolean isValidEmail(String email) {
        // 验证邮箱合法性的逻辑
        return email.matches("\\w{2,}@\\w{2,20}(\\.\\w{2,10}){1,2}");
    }
}
